﻿using System;
using System.Linq;
using System.Runtime.Serialization;

using SBPweb.PROvibe.Shared.Library.Base;

namespace SBPweb.PROvibe.Server.Library.Base
{

    [DataContract]
    public class Actor : IIndexable, INameable, IVersionable
    {

        #region Fields

        #endregion

        #region Properties

        [DataMember]
        public virtual int Id
        {
            get;
            set;
        }

        [DataMember]
        public virtual string Name
        {
            get;
            set;
        }

        [IgnoreDataMember]
        public virtual Version Version
        {
            get
            {
                if (string.IsNullOrEmpty(VersionAsString))
                {
                    return null;
                }
                return System.Version.Parse(VersionAsString);
            }
            set
            {
                VersionAsString = value.ToString();
            }
        }

        [DataMember]
        public virtual string VersionAsString
        {
            get;
            set;
        }

        #endregion

        #region Methods

        public int CompareTo(object obj)
        {
            return CompareTo(obj as INameable);
        }

        public int CompareTo(IIndexable other)
        {
            if (other == null)
            {
                return 0;
            }
            return this.Id.CompareTo(other.Id);
        }

        public int CompareTo(INameable other)
        {
            if (other == null)
            {
                return 0;
            }
            return this.Name.CompareTo(other.Name);
        }

        public int CompareTo(IVersionable other)
        {
            if (other == null)
            {
                return 0;
            }
            return this.Version.CompareTo(other.Version);
        }

        #endregion

    }

}